<?php

namespace api\page;

use think\Exception;
use think\Paginator;

class Page extends Paginator
{
    public function render()
    {
        try {
            $total = $this->total();
        } catch (Exception $e) {
            $total = null;
        }

        $data = $this->items->toArray();
        $page = [
            'item_total' => $total,
            'page_current' => $this->currentPage(),
            'page_next' => ($this->currentPage() + 1) > $this->lastPage() ? $this->lastPage() : ($this->currentPage() + 1),
            'page_pre' => ($this->currentPage() - 1) < 1 ? 1 : ($this->currentPage() - 1),
            'page_total' => $this->lastPage()
        ];

        return [
            'page' => $page,
            'list' => $data['data']
        ];
    }
}